const mongoose = require('mongoose')
const model = mongoose.model.bind(mongoose)
const Schema = mongoose.Schema
const ObjectId = Schema.Types.ObjectId

const fproductSchema = new Schema({
   _id: ObjectId,
   label: String,
   pid: {
       type: Number,
       default: 0

   },
   level: {
    type: Number,
    default: 0

   },
   deleted: {
    type: Boolean,
    default: false
   },
   children:[{
    type:ObjectId,
    ref:'Sproduct'
   }]
})

const sproductSchema = new Schema({
    _id:ObjectId,
    label:String,
    pid: {
        type: Number,
        default: 1
 
    },
    level: {
     type: Number,
     default: 1
 
    },
    deleted: {
     type: Boolean,
     default: false
    },
    children:[{
        type:ObjectId,
        ref:'Tproduct'
    }]
})

const tproductSchema = new Schema({
   _id:ObjectId,
   label:String,
   pid: {
    type: Number,
    default: 2
   },
   level: {
    type: Number,
    default: 2
   },
   deleted: {
    type: Boolean,
    default: false
   },
   states:[{
       type:ObjectId,
       ref:'State'
   }],
   dynamics:[{
       type:ObjectId,
       ref:'Dynamic'
   }]
})

const stateSchema = new Schema({
    _id:ObjectId,
    iteam: String,
    status: Boolean,
    system: String,
    apparent: String
 })

 const dynamicSchema = new Schema({
    _id:ObjectId,
    class: String,
    desc:String
 })
const Fproduct = model('Fproduct', fproductSchema )
const Sproduct = model('Sproduct', sproductSchema )
const Tproduct = model('Tproduct', tproductSchema)
const State = model('State', stateSchema)
const Dynamic = model('Dynamic', dynamicSchema)

module.exports =  { Fproduct, Sproduct, Tproduct, State, Dynamic  }